<?php
	class diabandb
	{
		public function Them($MaDiaBan = "", $TenDiaBan = "")
		{
			$sql = "INSERT INTO diaban(MaDiaBan, TenDiaBan)
					VALUES('$MaDiaBan', '$TenDiaBan')";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongKhachHang($MaDiaBan = "")
		{
			$sql = "SELECT * FROM khachhang WHERE 1";
			if($MaDiaBan != "")
				$sql.= " AND MaDiaBan = '$MaDiaBan'";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function CapNhat($MaDiaBan = "", $TenDiaBan = "", $MaDiaBanCu = "")
		{
			$sql = "UPDATE diaban 
					SET TenDiaBan = '$TenDiaBan', 
						MaDiaBan = '$MaDiaBan'
					WHERE MaDiaBan = '$MaDiaBanCu'";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaDiaBan = "")
		{
			$sql = "DELETE FROM diaban 
					WHERE MaDiaBan = '$MaDiaBan'";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM diaban";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaDiaBan = "", $TenDiaBan = "")
		{
			$sql = "SELECT * 
					FROM diaban 
					WHERE 1";
			
			if($MaDiaBan != "")
				$sql .= " AND MaDiaBan = '$MaDiaBan'";
				
			if($TenDiaBan != "")
				$sql .= " AND TenDiaBan = '$TenDiaBan'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>